── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ plotly::filter() masks dplyr::filter(), stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(zoo)
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
library(feasts)
Loading required package: fabletools
Registered S3 method overwritten by 'tsibble':
method from
as_tibble.grouped_df dplyr
library(tsibble)
Attaching package: 'tsibble'
The following object is masked from 'package:zoo':
index
The following object is masked from 'package:lubridate':
interval
The following objects are masked from 'package:base':
intersect, setdiff, union
Attaching package: 'parsnip'
The following object is masked from 'package:fabletools':
null_model
library(patchwork)
Previous assingment’s data.frame
#previous assignment's data tablepoudre_flow <-readNWISdv(siteNumber ="06752260", # Download data from USGS for site 06752260parameterCd ="00060", # Parameter code 00060 = discharge in cfs)startDate ="2013-01-01", # Set the start dateendDate ="2023-12-31") |># Set the end daterenameNWISColumns() |># Rename columns to standard names (e.g., "Flow", "Date")mutate(Date =yearmonth(Date)) |># Convert daily Date values into a year-month format (e.g., "2023 Jan")group_by(Date) |># Group the data by the new monthly Datesummarise(Flow =mean(Flow))
#assess = # of months as the testing set#cumulative = TRUE makes all the preceeding data the training data.training <-training(splits)testing <-testing(splits)
Use the prophet_reg(), and arima_reg() function to create a Prophet model for forecasting.
models <-map(mods, ~fit(.x, Flow ~ date, data = training))
frequency = 12 observations per 1 year
Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
#modeltime_table()models_tbl <-as_modeltime_table(models)#calibrate models- adds new column with test predictions and residuals(calibration_table <-modeltime_calibrate(models_tbl, testing, quiet =FALSE))
Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
refit_forecast <- refit_tbl |>modeltime_forecast(h ="12 months", actual_data = poudre_flow) |>plot_modeltime_forecast()#Refitting:#Retrieves your model and preprocessing steps#Refits the model to the new data#Recalculates any automations. This includes:#Recalculating the changepoints for the Earth Model#Recalculating the ARIMA and ETS parameters#Preserves any parameter selections. This includes:#Any other defaults that are not automatic calculations are used.
Use dataRetrieval to download daily streamflow for the next 12 months. Aggregate this data to monthly averages and compare it to the predictions made by your modeltime model.
library(dataRetrieval)poudre_24 <-readNWISdv(siteNumber ="06752260", # Download data from USGS for site 06752260parameterCd ="00060", # Parameter code 00060 = discharge in cfs)startDate ="2024-01-01", # Set the start dateendDate ="2024-12-31") |># Set the end daterenameNWISColumns() |># Rename columns to standard names (e.g., "Flow", "Date")mutate(Date =yearmonth(Date)) |># Convert daily Date values into a year-month format (e.g., "2023 Jan")group_by(Date) |># Group the data by the new monthly Datesummarise(Flow =mean(Flow))